<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增订单管理')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-ordersinfo-add">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">用户：</label>
                    <div class="col-sm-8">
                        <input name="userId" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">公寓：</label>
                    <div class="col-sm-8">
                        <input name="apartmentId" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">公寓信息：</label>
                    <div class="col-sm-8">
                        <textarea name="apartmentInfo" class="form-control" required></textarea>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">房东联系方式：</label>
                    <div class="col-sm-8">
                        <input name="hostNumber" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">房间图片：</label>
                    <div class="col-sm-8">
                        <input type="hidden" name="roomPicture">
                        <div class="file-loading">
                            <input class="form-control file-upload" id="roomPicture" name="file" type="file">
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">订单状态：</label>
                    <div class="col-sm-8">
                        <select name="orderStatus" class="form-control" th:with="type=${@dict.getType('order_state')}" required>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>
<!--            <div class="col-xs-12">-->
<!--                <div class="form-group">-->
<!--                    <label class="col-sm-3 control-label is-required">租金金额：</label>-->
<!--                    <div class="col-sm-8">-->
<!--                        <input name="rent" class="form-control" type="text" required>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">租金金额：</label>
                    <div class="col-sm-8">
                        <input name="rent" class="form-control" type="number" step="0.01" min="0" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">租期开始日期：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="startDate" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">租期结束日期：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="endDate" class="form-control" placeholder="yyyy-MM-dd" type="text">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">支付方式：</label>
                    <div class="col-sm-8">
                        <select name="paymentMethod" class="form-control" th:with="type=${@dict.getType('pay_type')}" required>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "ordersinfo/ordersinfo"
        // $("#form-ordersinfo-add").validate({
        //     focusCleanup: true
        // });
        $("#form-ordersinfo-add").validate({
            focusCleanup: true,
            rules: {
                rent: {
                    required: true,
                    number: true,
                    min: 0
                }
            },
            messages: {
                rent: {
                    required: "请输入租金金额",
                    number: "请输入有效的数字",
                    min: "租金金额必须大于或等于0"
                }
            }
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-ordersinfo-add').serialize());
            }
        }

        $("input[name='startDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='endDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(".file-upload").fileinput({
            uploadUrl: ctx + 'common/upload',
            maxFileCount: 1,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })
    </script>
</body>
</html>